package com.ruoyi.web.controller.mes;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysDept;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.kt.mes.domain.ProlSite;
import com.kt.mes.service.IProlSiteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产线工位Controller
 *
 * @author lzc
 * @date 2021-01-09
 */
@RestController
@RequestMapping("/mes/prosite")
public class ProlSiteController extends BaseController
{
    @Autowired
    private IProlSiteService prolSiteService;

    /**
     * 查询产线工位列表
     */
   // @PreAuthorize("@ss.hasPermi('mes:prosite:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProlSite prolSite)
    {
        startPage();
        List<ProlSite> list = prolSiteService.selectProlSiteList(prolSite);
        return getDataTable(list);
    }

    /**
     * 导出产线工位列表
     */
  //  @PreAuthorize("@ss.hasPermi('mes:prosite:export')")
    @Log(title = "产线工位", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProlSite prolSite)
    {
        List<ProlSite> list = prolSiteService.selectProlSiteList(prolSite);
        ExcelUtil<ProlSite> util = new ExcelUtil<ProlSite>(ProlSite.class);
        return util.exportExcel(list, "prosite");
    }

    /**
     * 获取产线工位详细信息
     */
   // @PreAuthorize("@ss.hasPermi('mes:prosite:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(prolSiteService.selectProlSiteById(id));
    }

    /**
     * 新增产线工位
     */
    //@PreAuthorize("@ss.hasPermi('mes:prosite:add')")
    @Log(title = "产线工位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProlSite prolSite)
    {
        //TODO
        //新增工位有问题
        return toAjax(prolSiteService.insertProlSite(prolSite));
    }

    /**
     * 修改产线工位
     */
  //  @PreAuthorize("@ss.hasPermi('mes:prosite:edit')")
    @Log(title = "产线工位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProlSite prolSite)
    {
        return toAjax(prolSiteService.updateProlSite(prolSite));
    }

    /**
     * 删除产线工位
     */
   // @PreAuthorize("@ss.hasPermi('mes:prosite:remove')")
    @Log(title = "产线工位", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(prolSiteService.deleteProlSiteByIds(ids));
    }


    @GetMapping("/treeselect")
    public AjaxResult treeselect()
    {

        return AjaxResult.success(prolSiteService.buildProlSiteTreeSelect());
    }
}
